package com.lyu.travel.core.repository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.concurrent.TimeUnit;

/**
 * @ProjectName: [travel]
 * @Package: [com.lyu.travel.core.repository]
 * @ClassName: [RedisTempleateRepo]
 * @Description: Redis数据访问连接测试持久层
 * @Author: [78483]
 * @CreateDate: [2020-05-16 17:18]
 * @UpdateUser: [78483]
 * @UpdateDate: [2020-05-16 17:18]
 * @UpdateRemark: [说明本次修改内容]
 * @Version: [v1.0]
 */
@Repository
public class RedisTempleateRepo {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    public void setKey(String key, String value) {
        ValueOperations<String, String> valueOperations = stringRedisTemplate.opsForValue();
        valueOperations.set(key, value, 1, TimeUnit.MINUTES);
    }

    public String getValue(String key) {
        ValueOperations <String, String> valueOperations = stringRedisTemplate.opsForValue();
        return valueOperations.get(key);
    }

}
